package com.imooc.security.data.provider.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.imooc.security.data.pojo.dto.UserResponseDTO;
import com.imooc.security.data.pojo.response.CommonResponseDto;
import com.imooc.security.data.pojo.utils.ResponseUtil;
import com.imooc.security.data.provider.entity.User;
import com.imooc.security.data.provider.service.UserService;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.lang.reflect.InvocationTargetException;

/**
 * @author Created By Houce
 * @date 2020-07-22 16:38
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserService userService;


    @GetMapping("/queryUserByUid")
    public CommonResponseDto<?> queryUserByUid(@RequestParam("uid")final String uid) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        final User user = userService.getOne(Wrappers.<User>lambdaQuery().eq(User::getUid, uid));
        UserResponseDTO userResponseDTO = new UserResponseDTO();
        if (null != user){
            BeanUtils.copyProperties(user,userResponseDTO);
        }
        return ResponseUtil.wrapSuccess(userResponseDTO);
    }
}
